package com.example.androidpattern.strategy;

import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.androidpattern.AppConstant;
import com.example.androidpattern.EMTagHandler;
import com.example.androidpattern.R;
import com.example.androidpattern.strategy.classes.CoolDisplay;
import com.example.androidpattern.strategy.classes.MagicAttack;
import com.example.androidpattern.strategy.classes.PhysicalAttack;
import com.example.androidpattern.strategy.classes.Role;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class StrategyActivity extends AppCompatActivity {

    private static final String TAG = "StrategyActivity";
    @BindView(R.id.btn_strategy)
    Button btnStrategy;
    @BindView(R.id.tv_strategy_info)
    TextView tvStrategyInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_strategy);
        ButterKnife.bind(this);

        setTitle("策略模式");

        tvStrategyInfo.setText(EMTagHandler.fromHtml(AppConstant.STRATEGY_DEFINE));
    }

    @OnClick(R.id.btn_strategy)
    public void onViewClicked() {
        Role roleA = new Role();
        roleA.setAttack(new PhysicalAttack())
                .setDisplay(new CoolDisplay());
        roleA.attack();
        roleA.display();

        Log.d(TAG, "onViewClicked: " + "===============");
        Role roleB = new Role();
        roleB.setDisplay(new CoolDisplay())
                .setAttack(new MagicAttack());

        roleB.attack();
        roleB.display();
    }
}